package com.hellobike.haxing.modules.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hellobike.haxing.modules.wms.constans.WmsConstans;
import com.hellobike.haxing.modules.wms.dto.SkuExtDto;
import com.hellobike.haxing.modules.wms.entity.SkuExt;
import com.hellobike.haxing.modules.wms.mapper.SkuExtMapper;
import com.hellobike.haxing.modules.wms.service.ISkuExtService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: t_wms_sku_ext
 * @Author: haxing-boot
 * @Date:   2020-01-09
 * @Version: V1.0
 */
@Service
public class SkuExtServiceImpl extends ServiceImpl<SkuExtMapper, SkuExt> implements ISkuExtService {

    @Override
    public Long getDefSkuLocId(Long skuId, Long warehouseId) {
        SkuExt sku = new SkuExt();
        sku.setSkuId(skuId);
        sku.setWarehouseId(warehouseId);
        Wrapper<SkuExt> wrapper = new QueryWrapper<>(sku);
        SkuExt skuExt = baseMapper.selectOne(wrapper);
        if (skuExt == null) {
            return WmsConstans.DEF_PUTAWAY_LOC_ID;
        }
        return skuExt.getLocId();
    }

    @Override
    public IPage<SkuExtDto> pageBySkuExtDto(Page<SkuExtDto> page, SkuExtDto skuExt) {
        return baseMapper.pageBySkuExtDto(page,skuExt);
    }

    @Override
    public SkuExt getBySkuId(Long skuId, Long warehouseId) {
        SkuExt sku = new SkuExt();
        sku.setSkuId(skuId);
        sku.setWarehouseId(warehouseId);
        Wrapper<SkuExt> wrapper = new QueryWrapper<>(sku);
        return baseMapper.selectOne(wrapper);
    }
}
